import { TargetClassifyType, TargetType } from "@/type"
import { request } from "umi"

const prefix = process.env.NODE_ENV == "development" ? `/api/kh/hyt/hd/` : '/api/'

interface CallbackData<T> {
  msg: '成功' | '失败',
  content: T
}

// login
export const login = (data: { user: string, pass: string }) => {
  return request(`${prefix}dl.php`, {
    method: 'POST',
    data
  })
}

// 获取分类列表
export const getTargetFl = () => {
  return request<CallbackData<TargetClassifyType[]>>(`${prefix}flhq.php`, {
    method: 'POST',
  })
}

// 新建分类
export const addTargetFl = (data: TargetClassifyType) => {
  return request(`${prefix}flxj.php`, {
    method: 'POST',
    data
  })
}

// 修改分类
export const editTargetFl = (data: TargetClassifyType & { gid: string }) => {
  return request(`${prefix}flxg.php`, {
    method: 'POST',
    data
  })
}

// 删除分类
export const delTargetFl = (data: Omit<TargetClassifyType, 'name'>) => {
  return request(`${prefix}flsc.php`, {
    method: 'POST',
    data
  })
}

// 获取指标
export const getTarget = (data: Pick<TargetType, 'flid'>) => {
  return request<CallbackData<TargetType[]>>(`${prefix}zbhq.php`, {
    method: 'POST',
    data
  })
}

// 新增指标
export const addTarget = (data: TargetType) => {
  return request(`${prefix}zbxj.php`, {
    method: 'POST',
    data
  })
}

// 修改指标
export const editTarget = (data: Pick<TargetType, 'flid' | 'id' | 'name'> & { gid: string }) => {
  return request(`${prefix}zbxg.php`, {
    method: 'POST',
    data
  })
}

// 删除指标
export const delTarget = (data: Pick<TargetType, 'id' | 'flid'>) => {
  return request(`${prefix}zbsc.php`, {
    method: 'POST',
    data
  })
}


// 获取科目
export const kmhq = () => {
  return request(`${prefix}kmhq.php`, {
    method: 'POST'
  })
}

// 新增科目
export const kmlr = (data: { id: string, name: string }) => {
  return request(`${prefix}kmlr.php`, {
    method: 'POST',
    data
  })
}

// 删除科目
export const kmsc = (data: { id: string }) => {
  return request(`${prefix}kmsc.php`, {
    method: 'POST',
    data
  })
}

// 时间录入
export const sjlr = (data: { time: string }) => {
  return request(`${prefix}sjlr.php`, {
    method: 'POST',
    data
  })
}

// 时间获取
export const sjhq = () => {
  return request(`${prefix}sjhq.php`, {
    method: 'POST',
  })
}

// 时间科目
export const sjkm = (data: { time: string, y: 1 | 2 | 3 }) => {
  return request(`${prefix}sjkm.php`, {
    method: 'POST',
    data
  })
}

// 时间删除
export const sjsc = (data: { time: string }) => {
  return request(`${prefix}sjsc.php`, {
    method: 'POST',
    data
  })
}

// 时间修改
export const sjxg = (data: { time: string, km: string, value: string }) => {
  return request(`${prefix}sjxg.php`, {
    method: 'POST',
    data
  })
}

// 计算指标
export const jszb = (data: { time: string, flid: string }) => {
  return request(`${prefix}jszb.php`, {
    method: 'POST',
    data
  })
}

export const jssc = (data: { time: string }) => {
  return request(`${prefix}jssc.php`, {
    method: 'POST',
    data
  })
}


export const jsbc = (data: { time: string }) => {
  return request(`${prefix}jsbc.php`, {
    method: 'POST',
    data
  })
}

export const cxlq_c_n = () => {
  return request(`${prefix}cxlq_c_n.php`, {
    method: 'POST'
  })
}

export const cxlq_c_zb = (data: { time: string, flid: string }) => {
  return request(`${prefix}cxlq_c_zb.php`, {
    method: 'POST',
    data
  })
}

export const cxqst = (data: { gs: string }) => {
  return request(`${prefix}cxqst.php`, {
    method: 'POST',
    data
  })
}

export const shouye = () => {
  return request(`${prefix}shouye.php`, {
    method: 'POST',
  })
}